import React, { Component } from 'react';
import { Link,BrowserRouter,HashRouter,NavLink,Redirect } from 'react-router-dom';
import '../style/less/main.css';
import axios from '../api/index';
import Login from './Login';
import { Menu, Icon, Button } from 'antd';

const SubMenu = Menu.SubMenu;


class SubNav extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            reMock:null
        }
    }
    state = {
        collapsed: false,
      }
    componentWillMount(){
        axios.api.mockData2().then((res)=>{
            let mock = res.array;
            this.setState({
                reMock:mock
            })
        })
    }
      toggleCollapsed = () => {
        this.setState({
          collapsed: !this.state.collapsed,
        });
      }
    
      render() {
       var reList = this.state.reMock;
        if(reList){
            var listItem = reList.map((item,index)=>
                <SubMenu key={item.id} title={<span><Icon type="mail" /><span>{item.name}</span></span>}>
                    {
                        item.list.map((subItem,i)=>
                        <Menu.Item key={subItem.id}>
                        <NavLink to={subItem.href}><Icon type="team" />{subItem.name}</NavLink>
                    </Menu.Item>
                        )
                    }
                </SubMenu>
            )
        }
        return (
       
                 <div  style={{ width: 180,height:'calc(100% - 82px)' ,position:'absolute'}}
                >
                    <Menu
                    defaultSelectedKeys={['1']}
                    defaultOpenKeys={['sub1']}
                    mode="inline"
                    theme="dark"
                    inlineCollapsed={this.state.collapsed}
                    style={{minHeight:'100%'}}
                    >
                    {listItem}
                    </Menu>
                </div>
             
        );
      }
}

export default SubNav;
